package com.niit.session8;

import java.util.Scanner;

public class UserLogin {
//	已知正确的用户名密码，请实现用户登录验证。验证次数最多3次。
	public static void main(String[] args) {
		String username = "Trout";
		String password = "123456";
		Scanner sc = new Scanner(System.in);
		System.out.println("请输入用户名：");
		String name = sc.next();
		System.out.println("请输入密码：");
		String pass = sc.next();
		for (int i = 0; i <= 2; i++) {
//			equals()用于比较两个字符串是否相同，并且区分大小写
			if(username.equals(name) && password.equals(pass)) {
				System.out.println("登录成功");
				break;
			}else {
				if((2-i) == 0) {
					break;
				}
				System.out.println("登录失败，你还有"+(2-i)+"次机会");
				System.out.println("请输入用户名：");
				name = sc.next();
				System.out.println("请输入密码：");
				pass = sc.next();
			}
		}
		
		
		
		
		
	}

}
